
package net.qiqbframework.messaging.annotation;

import net.qiqbframework.messaging.Message;

public class PayloadParameterResolver implements HandlerParameterResolver<Object> {

    private final Class<?> payloadType;


    public PayloadParameterResolver(Class<?> payloadType) {
        this.payloadType = payloadType;
    }

    @Override
    public Object resolveParameter(Message<?> message) {
        return message.getPayload();
    }

    @Override
    public boolean support(Message<?> message) {
        return message.getPayloadType() != null && payloadType.isAssignableFrom(message.getPayloadType());
    }

    @Override
    public Class<?> supportedPayloadType() {
        return payloadType;
    }
}
